package com.iss.apartmentmanage.controller.check;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iss.apartmentmanage.entity.CheckinRecord;
import com.iss.apartmentmanage.entity.RoomManage;
import com.iss.apartmentmanage.model.MyResponseData;
import com.iss.apartmentmanage.model.BaseModel;
import com.iss.apartmentmanage.model.RecordWithRoomForAll;
import com.iss.apartmentmanage.service.impl.CheckServiceImpl;
import com.iss.apartmentmanage.utils.MyJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/check")
public class CheckOutController {
    @Autowired
    CheckServiceImpl checkService;

    /**
     * 查询全部空闲的房间
     * @param pageNum
     * @param pageSize
     * @param
     * @return
     */
    @RequestMapping(value = "/selectRoomForCheckOut",method = RequestMethod.POST)
    public String selectRoomForCheckOut(Integer pageNum, Integer pageSize,
                                        Integer areaId, String roomType,  String roomName,
                                        Double priceFrom, Double priceTo, Integer status){
        MyResponseData myResponseData = new MyResponseData();
        List<RecordWithRoomForAll> checkinRecords=checkService.selectRoomForCheckOut(pageNum,pageSize,roomType,roomName,
         areaId, priceFrom, priceTo, status);

            if(checkinRecords!=null) {
                myResponseData.setObject(checkinRecords);
                myResponseData.setErrorCode(1);
                myResponseData.setStatus("查询成功");
            }else{
                myResponseData.setErrorCode(-1);
                myResponseData.setStatus("查询失败");
            }
            return MyJson.getJson(myResponseData);
    }

    /**
     * 办理退房
     * @param checkinRecord
     * @return
     */
    @RequestMapping(value = "/updateRoomForFree",method=RequestMethod.POST)
    public String updateRoomForFree(@RequestBody CheckinRecord checkinRecord){
        MyResponseData myResponseData = new MyResponseData();
        Integer count = checkService.updateRoomForFree(checkinRecord);
        if(count==1) {
            myResponseData.setErrorCode(1);
            myResponseData.setStatus("退房成功");
        }
        return MyJson.getJson(myResponseData);
    }

}
